local jizhi = fk.CreateSkill {
  name = "th_jizhi",
  max_turn_use_time = 1,
}



jizhi:addEffect("viewas", {
  anim_type = "control",
  pattern = "nullification",
  mute_card = false,
  handly_pile = true,
  card_num = 1,
  filter_pattern = {
    min_num = 1,
    max_num = 1,
    pattern = ".|.|black"
  },
  view_as = function(self, player,cards)
    if #cards ~= 1 then return end
    local card = Fk:cloneCard("nullification")
    card.skillName = jizhi.name
    card:addSubcards(cards)
    return card
  end,
  before_use = function(self, player, use)
    use.disresponsiveList = player.room:getAlivePlayers(false)
  end,
  enabled_at_play = Util.FalseFunc,
  enabled_at_response = function(self, player, response)
    return not response and not player:isKongcheng()
  end,
  enabled_at_nullification = function(self, player)
    return not player:isKongcheng()
  end
}, { check_skill_limit = true })

jizhi:addEffect(fk.CardUseFinished, {
  is_delay_effect = true,
  mute = true,
  can_trigger = function(self, event, target, player, data)
    if target == player and player:isAlive() and data.cardsResponded then
      for _, card in ipairs(data.cardsResponded) do
        if table.contains(card.skillNames, jizhi.name) then return true end
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = table.filter(data.cardsResponded, function(card) return table.contains(card.skillNames, jizhi.name) end)
    if #cards < 1 then return end
    local targets = {}
    room.logic:getEventsOfScope(GameEvent.UseCard, 1, function(e)
      local use = e.data
      local user = use.from
      if #cards == 0 then return true end
      if table.contains(cards, use.card) and use.responseToEvent and use.toCard == data.card and user and user:isAlive() and user ~= player then
        table.removeOne(cards, use.card)
        table.insert(targets, user)
      end
      return false
    end, Player.HistoryTurn)
    if #targets ~= 0 then
      for _, p in ipairs(targets) do
        room:useVirtualCard("duel", nil, player, p, jizhi.name)
      end
    end
  end,
})

Fk:loadTranslationTable{
  ["th_jizhi"] = "犄峙",
  [":th_jizhi"] = "每回合限一次，你可以将黑色牌当不可响应的【无懈可击】使用，若如此做，目标牌结算后视为使用者对你使用一张【决斗】。",

  ["#th_jizhi"] = "犄峙：将黑色牌当不可响应的【无懈可击】使用，若如此做，目标牌结算后视为使用者对你使用一张【决斗】",
}

return jizhi